/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.register;

import controller.login.CheckTaiKhoan;
import dao.LoaiTaiKhoanDAO;
import dao.TaiKhoanDAO;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Random;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.imageio.ImageIO;
import pojo.Loaitaikhoan;
import pojo.Taikhoan;
import template.choosePage;

/**
 *
 * @author vinh
 */
@ManagedBean(name = "register")
@SessionScoped
public class CheckRegister {

    /**
     * Creates a new instance of CheckRegister
     */
    static public String hoten = null;
    static public String noisong = "Long An";
    static public String tendangnhap = null;
    static public String pass = null;
    static public String conpass = null;
    static public int ngaysinh = 1;
    static public int thangsinh = 1;
    static public int namsinh = 2000;
    public boolean dangkithanhcong = false;

  
    public  String getHoten() {
        return hoten;
    }

    
    public  void setHoten(String aHoten) {
        hoten = aHoten;
    }

   
    public  String getNoisong() {
        return noisong;
    }

    
    public  void setNoisong(String aNoisong) {
        noisong = aNoisong;
    }

   
    public  String getTendangnhap() {
        return tendangnhap;
    }

    
    public  void setTendangnhap(String aTendangnhap) {
        tendangnhap = aTendangnhap;
    }

    public  String getPass() {
        return pass;
    }

    
    public  void setPass(String aPass) {
        pass = aPass;
    }

    public  String getConpass() {
        return conpass;
    }

   
    public  void setConpass(String aConpass) {
        conpass = aConpass;
    }

    
    public  int getNgaysinh() {
        return ngaysinh;
    }

   
    public  void setNgaysinh(int aNgaysinh) {
        ngaysinh = aNgaysinh;
    }

    
    public  int getThangsinh() {
        return thangsinh;
    }

    
    public  void setThangsinh(int aThangsinh) {
        thangsinh = aThangsinh;
    }

    public  int getNamsinh() {
        return namsinh;
    }

   
    public  void setNamsinh(int aNamsinh) {
        namsinh = aNamsinh;
    }

    static public  boolean checkTDN(String tdn) {
        return !CheckTaiKhoan.checkusername(tdn);
    }

    public boolean isDangkithanhcong() {
        return dangkithanhcong;
    }

   
    public void setDangkithanhcong(boolean dangkithanhcong) {
        this.dangkithanhcong = dangkithanhcong;
    }

    public void setLayInfo() {
        if(CheckTaiKhoan.taikhoan!=null)
        {
        hoten = CheckTaiKhoan.taikhoan.getHoten();
        noisong = CheckTaiKhoan.taikhoan.getNoisong();
        tendangnhap = CheckTaiKhoan.taikhoan.getTendangnhap();
        pass = CheckTaiKhoan.taikhoan.getMatkhau();
        ngaysinh = CheckTaiKhoan.taikhoan.getNgaysinh().getDate();
        thangsinh = CheckTaiKhoan.taikhoan.getNgaysinh().getMonth()+1;
        namsinh = CheckTaiKhoan.taikhoan.getNgaysinh().getYear()+1900;
        }
    }

    public void setTaiKhoan() {
        LoaiTaiKhoanDAO ltkdao = new LoaiTaiKhoanDAO();
        Loaitaikhoan ltk = ltkdao.get("user");
        Taikhoan tk= new Taikhoan();
        tk.setHoten(hoten);
        tk.setLoaitaikhoan(ltk);
        tk.setNoisong(noisong);
        tk.setTendangnhap(tendangnhap);
        tk.setMatkhau(pass);
        Date aa = new Date();
        aa.setDate(ngaysinh);
        aa.setMonth(thangsinh - 1);
        aa.setYear(namsinh - 1900);
        tk.setNgaysinh(aa);

        TaiKhoanDAO tkdao = new TaiKhoanDAO();
        List<Taikhoan> listtk = tkdao.getList();
        if (choosePage.page.equals("DangKi")) {
            int tkmax = 0;
            for (int i = 0; i < listtk.size(); i++) {
                int matk = Integer.parseInt(listtk.get(i).getMataikhoan().replaceFirst("tk", ""));
                if (tkmax < matk) {
                    tkmax = matk;
                }
            }
            tkmax++;
            tk.setMataikhoan("tk" + tkmax);
        }
        if(choosePage.page.equals("UpdateInfo"))
        {
            tk.setMataikhoan(CheckTaiKhoan.taikhoan.getMataikhoan());
            CheckTaiKhoan.taikhoan=tk;
        }
        tkdao.saveorupdate(tk);
          choosePage.page="TrangChu";
    }
   
}
